package Review;

import java.util.HashMap;
import java.util.Map;

public class test35 {

	public static void main(String[] args) {
		String str="abacccdeff";
		System.out.println(findNotRepeatingChar(str));
		System.out.println(new FindNotRepeatingChar().findFirstNotRepeat(str.toCharArray()));
	}
	public static char findNotRepeatingChar(String str){
		if(str==null||str.length()==0){
			return '\0';
		}
		char[] ch = str.toCharArray();
		Map<Character, Integer> map = new HashMap<Character,Integer>();
		for(int i=0;i<ch.length;i++){
			if(map.get(ch[i])==null){
				map.put(ch[i], 1);
			}
			else{
				map.put(ch[i],map.get(ch[i])+1);
			}
		}
		for(int i=0;i<ch.length;i++){
			if(map.get(ch[i])==1){
				return ch[i];
			}
		}
		return '\0';
	}
 
}

class FindNotRepeatingChar{
	public char findFirstNotRepeat(char []ch ){
		if(ch == null || ch.length <= 0){
			return '\0';
		}
		Map<Character, Integer> map = new HashMap<Character, Integer>();
		for (int i = 0; i < ch.length; i++) {
			if(map.get(ch[i]) == null){
				map.put(ch[i], 1);
			}else{
				map.put(ch[i],map.get(ch[i])+1);
			}
		}
		
		for (int i = 0; i < ch.length; i++) {
			if(map.get(ch[i]) == 1){
				return ch[i];
			}
		}
		return '\0';
	}
}